package com.schoolvisitors.controller;

import com.schoolvisitors.service.ImgService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/src")
public class ImgController {
    private final ImgService imgService;

    public ImgController(ImgService imgService) {
        this.imgService = imgService;
    }

    @GetMapping("/img/{filename:.+}")
    public ResponseEntity<byte[]> serveImage(@PathVariable String filename) {
        return imgService.getMedia(filename);
    }
}
